package cn.opopopo.design_pattern_learn.行为型.command;

// 调温命令（带参数）
public class SetTemperatureCommand implements Command {
    private AirConditioner ac;
    private int previousTemp;
    private int targetTemp;

    public SetTemperatureCommand(AirConditioner ac, int temp) {
        this.ac = ac;
        this.targetTemp = temp;
    }

    @Override
    public void execute() {
        previousTemp = ac.getTemperature(); // 保存之前状态
        ac.setTemperature(targetTemp);
    }

    @Override
    public void undo() {
        ac.setTemperature(previousTemp);
    }
}